<template>
    <view :class="'h2w h2w-' + nodes.theme + ' ' + (writing ? 'h2w-writing' : '')">
        <view class="h2w__main">
            <decode :nodes="nodes" class="decode" />
        </view>
    </view>
</template>

<script>
import decode from './decode';
import towxml from './index.js';
const app = getApp();
export default {
    components: {
        decode
    },
    data() {
        return {
            nodes: {
                theme: ''
            },
            someData: {}
        };
    },
    options: {
        styleIsolation: 'shared'
    },
    props: {
        type: {
            type: String,
            default: 'markdown'
        },
        content: {
            type: String,
            default: {}
        },
        writing: {
            type: Boolean,
            default: false
        }
    },
    methods: {},
    created: function () {},
    watch: {
        content: {
            handler: function (content) {
                let type = this.type ? this.type : 'markdown';
                let nodes = towxml(content, type, {
                    theme: 'light'
                });
                if (this.writing) {
                    const cursor = {
                        tag: 'image',
                        attrs: {
                            src: '/others/static/images2/cursor.gif',
                            style: 'width: 8rpx; height: 32rpx; position: relative; top: -2rpx;'
                        }
                    };
                    if (nodes.children) {
                        nodes.children.push(cursor);
                    }
                }
				this.nodes = nodes;
            },

            immediate: true
        }
    }
};
</script>
<style>
@import './style/main.css';
@import './style/theme/light.css';
@import './style/theme/dark.css'; /**基础风格样式**/

/**主题配色（浅色样式）**/

/**主题配色（深色样式）**/
</style>
